import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ClockManager } from "../../manager/ClockManager";
import { Global } from "../../../../com/gengine/global/Global";
import { Cache } from "../../cache/Cache";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ItemData } from "../../resource/info/ItemData";
import { QuickBuyWindow } from "../common/QuickBuyWindow";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { MsgManager } from "../../manager/MsgManager";
import { ResFileConst } from "../../resource/ResFileConst";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class CellHappyView
    
    export  class CellHappyView extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.resetPosition();
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            var loc2=null;
            var loc4=null;
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            loc1.bold = true;
            loc2 = new Object /* flash.display.Sprite */();
            this.addChild(loc2);
            this._fireProgressBg = new Object /* flash.display.Bitmap */();
            this._fireProgressBg.x = 49;
            this._fireProgressBg.y = 20;
            loc2.addChild(this._fireProgressBg);
            this._bmpProgress = new Object /* flash.display.Bitmap */();
            this._bmpProgress.x = 49;
            this._bmpProgress.y = 27;
            loc2.addChild(this._bmpProgress);
            this._fireProgressLeft = new Object /* flash.display.Bitmap */();
            this._fireProgressLeft.y = 10;
            this._fireProgressLeft.x = 2;
            loc2.addChild(this._fireProgressLeft);
            this._bmpProgressLight = new Object /* flash.display.Bitmap */();
            this._bmpProgressLight.x = 25;
            this._bmpProgressLight.y = 10;
            loc2.addChild(this._bmpProgressLight);
            this._tfProgress = ObjCreate.createTextField("0/1314", 60, 8, 130, 20, loc2, GlobalStyle.textFormat2);
            this._fireBtn = ObjCreate.createGButton(Language.getString(57437), 95, 44, 75, 22, this, "ButtonRedMini");
            this._fireBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onFireBtnClik);
            var loc3=GlobalClass.getBitmap(ImagesConst.Fire);
            loc3.x = 72;
            loc3.y = 39;
            this.addChild(loc3);
            (loc4 = GlobalClass.getBitmap(ImagesConst.Fire)).x = 171;
            loc4.y = 39;
            this.addChild(loc4);
            LoaderHelp.addResCallBack(this.getResName(), this.updateBitmapData);
            return;
        }

        protected onFireBtnClik(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=ClockManager.instance.nowDate.time;
            if (loc1 - this.lastTime > 3000 || Global.isDebugModle) 
            {
                loc2 = Cache.instance.pack.backPackCache.getItemsByJudge(ItemsUtil.isFireworkProp, true);
                if (loc2.length > 0) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, loc2[0] as ItemData));
                    this.lastTime = loc1;
                }
                else if (QuickBuyWindow.instance.updateWindow(ECategory._ECategoryProp, EProp._EPropFirework, 1, -1, true)) 
                {
                    QuickBuyWindow.instance.updateDefaultAmount(1);
                    QuickBuyWindow.instance.show();
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(43201));
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(43202));
            }
            return;
        }

        protected getResName(): string
        {
            return ResFileConst.CellHappy;
        }

        protected updateBitmapData(): void
        {
            this._fireProgressBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.CellHappyBg);
            this._fireProgressLeft.bitmapData = GlobalClass.getBitmapData(ImagesConst.CellHappyLeft);
            this._bmpProgressLight.bitmapData = GlobalClass.getBitmapData(ImagesConst.CellHappyLight);
            this._bmpProgressOverData = GlobalClass.getBitmapData(ImagesConst.CellHappyOver);
            this._bmpdProgress = this._bmpProgressOverData.clone();
            this._isLoadCompl = true;
            this.updateView();
            return;
        }

        public updateCellHappy(arg1: int, arg2: int): void
        {
            this.cellHapyy = arg1;
            this.maxCellHappy = arg2;
            this.updateView();
            return;
        }

        protected updateView(): void
        {
            if (this._isLoadCompl) 
            {
                this.updateRomanic(this.cellHapyy, this.maxCellHappy);
            }
            return;
        }

        protected updateRomanic(arg1: int, arg2: int): void
        {
            var loc1=arg1 / arg2;
            loc1 = loc1 < 0 ? 0 : loc1;
            loc1 = loc1 > 1 ? 1 : loc1;
            var loc2=0;
            this._bmpProgress.bitmapData = null;
            this._bmpdProgress.dispose();
            if (loc1 > 0) 
            {
                if ((loc2 = loc1 * this._bmpProgressOverData.width) >= 1) 
                {
                    this._bmpdProgress = new Object /* flash.display.BitmapData */(loc2, this._bmpProgressOverData.height, true, 16777215);
                    this._bmpdProgress.draw(this._bmpProgressOverData, null, null, null, new Object /* flash.geom.Rectangle */(0, 0, loc2, this._bmpProgressOverData.height));
                    this._bmpProgress.bitmapData = this._bmpdProgress;
                }
            }
            this._bmpProgressLight.x = loc2 + 30;
            this._tfProgress.text = this._desText + "：" + arg1 + "/" + arg2;
            return;
        }

        public set desText(arg1: string)
        {
            this._desText = arg1;
            return;
        }

        public resetPosition(): void
        {
            this.x = 260;
            this.y = 10;
            return;
        }

        protected /* var */_tfProgress: Object /* flash.text.TextField */;

        protected /* var */_bmpProgressOverData: Object /* flash.display.BitmapData */;

        protected /* var */_bmpProgressLight: Object /* flash.display.Bitmap */;

        protected /* var */_bmpProgress: Object /* flash.display.Bitmap */;

        protected /* var */_bmpdProgress: Object /* flash.display.BitmapData */;

        protected /* var */_fireProgressLeft: Object /* flash.display.Bitmap */;

        protected /* var */_fireProgressBg: Object /* flash.display.Bitmap */;

        protected /* var */_desText: string="";

        protected /* var */_fireBtn: GButton;

        /* internal */ /* var */lastTime: int=-2147483648;

        protected /* var */_isLoadCompl: Boolean=false;

        protected /* var */cellHapyy: int=0;

        protected /* var */maxCellHappy: int=1314;
    }
